package com.naizhuai.ui.management.presenter;


import com.naizhuai.AppContext;
import com.naizhuai.Model.db.eneity.ManageNoteBean;
import com.naizhuai.network.Config;
import com.naizhuai.network.RetrofitServerFactory;
import com.naizhuai.network.apistore.CompanyManageRequest;
import com.naizhuai.network.entity.ResultResponse;
import com.naizhuai.ui.entity.management.CompanyBean;
import com.naizhuai.ui.entity.management.ManagementMainMsgBean;
import com.naizhuai.ui.entity.management.RequestJoinMessageBean;
import com.naizhuai.ui.entity.management.DepartmentBean;
import com.naizhuai.util.RxUtils;

import java.util.List;

import retrofit2.http.Query;
import rx.Observable;

/**
 * 管理接口的实现类
 * Created by code_han on 2018/1/25.
 */

public class CompanyManageDataApiStoreIml implements CompanyManageDataApiStore {


    private static CompanyManageDataApiStore INSTANCE = null;

    private CompanyManageDataApiStoreIml() {
    }

    public static CompanyManageDataApiStore getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new CompanyManageDataApiStoreIml();
        }
        return INSTANCE;
    }

    @Override
    public Observable<List<DepartmentBean>> getTeamListByPerIds(String companyId) {
        return createBaseClass().getTeamListByPerIds(companyId)
                .compose(RxUtils.applySchedulers());
    }

    @Override
    public Observable<DepartmentBean> getTeamDetailsByIds(String companyId, String teamId) {
        return createBaseClass().getTeamDetailsByIds(companyId, teamId)
                .compose(RxUtils.applySchedulers());
    }

    @Override
    public Observable<List<DepartmentBean>> getTeamListInCompanyByIds(String companyId) {
        return createBaseClass().getTeamListInCompanyByIds(companyId)
                .compose(RxUtils.applySchedulers());
    }

    @Override
    public Observable<ManagementMainMsgBean> getCompanyMainMsgByIds(String companyId) {
        return createBaseClass().getCompanyMainMsgByIds(companyId)
                .compose(RxUtils.applySchedulers());
    }

    @Override
    public Observable<CompanyBean> getCompanyDetailsByIds(String companyId) {
        return createBaseClass().getCompanyDetailsByIds(companyId)
                .compose(RxUtils.applySchedulers());
    }

    @Override
    public Observable<CompanyBean> getCompanyMembersByIds(String companyId) {
        return createBaseClass().getCompanyMembersByIds(companyId)
                .compose(RxUtils.applySchedulers());
    }

    @Override
    public Observable<List<ManageNoteBean>> getApplyStatus(String applyIdList) {
        return createBaseClass().getApplyStatus(applyIdList)
                .compose(RxUtils.applySchedulers());
    }


    @Override
    public Observable<String> deleteTeamFromCompanyByIds(String teamId) {
        return createBaseClass().deleteTeamFromCompanyByIds(teamId)
                .compose(RxUtils.applySchedulers());
    }

    @Override
    public Observable<String> deletePersonFromCompanyByIds(String departmentId, String teamId, String removeUsersId, int removeType, int isInitiative) {
        return createBaseClass().deletePersonFromCompanyByIds(departmentId, teamId, removeUsersId, removeType, isInitiative)
                .compose(RxUtils.applySchedulers());
    }


    @Override
    public Observable<DepartmentBean> updatePersonPositionInTeamByIds(String companyId, String teamId, String deleteUserId, String status) {
        return createBaseClass().updatePersonPositionInTeamByIds(companyId, teamId, deleteUserId, status)
                .compose(RxUtils.applySchedulers());
    }

    @Override
    public Observable<CompanyBean> updateCompanyMsg(CompanyBean company) {
        return createBaseClass().updateCompanyMsg(company)
                .compose(RxUtils.applySchedulers());
    }

    @Override
    public Observable<String> insertPersonAddCompanyByIds(String inviteUserIds, int groupType, String departmentId, String power, String groupId) {
        return createBaseClass().insertPersonAddCompanyByIds(inviteUserIds, groupType, departmentId, power, groupId)
                .compose(RxUtils.applySchedulers());
    }

    @Override
    public Observable<String> updateTeamMsg(String departmentId, String departmentName) {
        return createBaseClass().updateTeamMsg(departmentId, departmentName)
                .compose(RxUtils.applySchedulers());
    }

    @Override
    public Observable<String> requestToJoinCompany(String applyCompanyId, String applyDepartmentId,String content) {
        return createBaseClass().requestToJoinCompany(applyCompanyId, applyDepartmentId, content)
                .compose(RxUtils.applySchedulers());
    }

    @Override
    public Observable<String> updateUserInfo(String changedUid, String departmentId, String power) {
        return createBaseClass().updateUserInfo(changedUid, departmentId, power)
                .compose(RxUtils.applySchedulers());
    }

    @Override
    public Observable<String> updateUserInfoFromCompany(String changedUid, String power) {
        return createBaseClass().updateUserInfoFromCompany(changedUid, power)
                .compose(RxUtils.applySchedulers());
    }

    @Override
    public Observable<String> createTeam(String groupName, String leadingUid, String inviteUsersIds) {
        return createBaseClass().createTeam(groupName, leadingUid, inviteUsersIds)
                .compose(RxUtils.applySchedulers());
    }

    @Override
    public Observable<List<RequestJoinMessageBean>> getRequestMessageList(String companyId, int offset, int limit) {
        return createBaseClass().getRequestMessageList(companyId, offset, limit)
                .compose(RxUtils.applySchedulers());
    }


    @Override
    public Observable<List<CompanyBean>> getCompanyMessageList(@Query("offset") int offset, @Query("limit") int limit) {
        return createBaseClass().getCompanyMessageList(offset, limit)
                .compose(RxUtils.applySchedulers());
    }


    @Override
    public Observable<String> handleApply( String applyRes, String applyIdList) {
        return createBaseClass().handleApply(applyRes,applyIdList)
                .compose(RxUtils.applySchedulers());
    }

    private CompanyManageRequest createBaseClass() {
        return RetrofitServerFactory.create(AppContext.getInstance(), CompanyManageRequest.class, Config.TEST_ACTION_BASE_URL);
    }
}
